import request from '@/config/axios'
import type { Dayjs } from 'dayjs';

/** 设备秘钥信息 */
export interface DeviceKey {
          id: number; // 密钥ID
          secretKey?: string; // 密钥内容
          status?: number; // 状态
          deviceId: number; // 绑定设备
          remark: string; // 备注
  }

/** 批量生成设备秘钥参数 */
export interface BatchCreateDeviceKeyReq {
  count: number; // 生成数量
  remark?: string; // 备注，默认为"批量生成"
}

// 设备秘钥 API
export const DeviceKeyApi = {
  // 查询设备秘钥分页
  getDeviceKeyPage: async (params: any) => {
    return await request.get({ url: `/yunkong/device-key/page`, params })
  },

  // 查询设备秘钥详情
  getDeviceKey: async (id: number) => {
    return await request.get({ url: `/yunkong/device-key/get?id=` + id })
  },

  // 新增设备秘钥
  createDeviceKey: async (data: DeviceKey) => {
    return await request.post({ url: `/yunkong/device-key/create`, data })
  },

  // 修改设备秘钥
  updateDeviceKey: async (data: DeviceKey) => {
    return await request.put({ url: `/yunkong/device-key/update`, data })
  },

  // 删除设备秘钥
  deleteDeviceKey: async (id: number) => {
    return await request.delete({ url: `/yunkong/device-key/delete?id=` + id })
  },

  /** 批量删除设备秘钥 */
  deleteDeviceKeyList: async (ids: number[]) => {
    return await request.delete({ url: `/yunkong/device-key/delete-list?ids=${ids.join(',')}` })
  },

  // 批量生成设备秘钥
  batchCreateDeviceKey: async (data: BatchCreateDeviceKeyReq) => {
    return await request.post({ url: `/yunkong/device-key/batch-create`, data })
  },

  // 导出设备秘钥 Excel
  exportDeviceKey: async (params) => {
    return await request.download({ url: `/yunkong/device-key/export-excel`, params })
  }
}